# -*- coding: UTF8 -*-
# Author: Sakurazaki
# (Aitor Martin. @arienai_ne - sakurazaki.setsunita@gmail.com)

import gamestate as gs

class GameStateMachine(object):

    def __init__(self):
        self.keep = True
        self.currentState = gs.MainMenu()
        self.prevState = None
        self.nextState = None

    def changeState(self):
        self.prevState = self.currentState
        self.currentState = self.nextState
        self.nextState = None

    def handleEvent(self, ev):
        self.currentState.handleEvent(ev)

    def update(self, delta):
        if self.nextState:
            self.changeState()

        self.currentState.update(delta)

        if not self.currentState.keep:
            self.keep = False

    def render(self, screen):
        self.currentState.render()
        screen.blit(self.currentState.surface, self.currentState.rect)
